﻿using CheatMenu.Managers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using CheatMenu.Utils;
using Logger = BepInEx.Logger;
using BepInEx.Logging;

namespace CheatMenu.Menus
{
    public class MenuNotifications : MenuBase
    {
        private GUIStyle defaultFontLabelStyle;
        private GUIStyle defaultFontLabelHeaderStyle;

        private float beginTime;
        private string headerText;
        private string bodyText;

        public static float ShownTimeout { get; set; } = 10f;

        public MenuNotifications() : base("Notifications")
        {
            ForceGUIEnabled = true;
        }

        protected override Vector2 InitializeSize()
        => new Vector2((GUIManager.ControlWidth) + (GUIManager.PaddingSize * 2), (GUIManager.ControlHeight) + (GUIManager.PaddingSize * 2));

        protected override void InitializeGUI()
        {
            defaultFontLabelStyle = new GUIStyle(GUI.skin.label)
            {
                fontSize = GUIManager.ControlFontSize,
                wordWrap = false,
                normal = new GUIStyleState
                {
                    textColor = GUIManager.LabelColor
                }
            };

            defaultFontLabelHeaderStyle = new GUIStyle(GUI.skin.label)
            {
                fontSize = GUIManager.ControlFontSize,
                wordWrap = false,
                fontStyle = FontStyle.Bold,
                normal = new GUIStyleState
                {
                    textColor = GUIManager.LabelHeaderColor
                }
            };
        }

        protected override void MenuWindow(int id)
        {
            GUILayout.BeginHorizontal();
            {
                GUILayout.BeginVertical(GUI.skin.box);
                {
                    GUILayout.Label(headerText, defaultFontLabelHeaderStyle);
                    GUILayout.Label(bodyText, defaultFontLabelStyle);
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();

            if ((Time.realtimeSinceStartup - beginTime) > ShownTimeout)
                Shown = false;
        }

        public void PushNotification(string header, string body)
        {
            if (StateManager.LastSceneName == "Start")
                WindowOffset = new Vector2(0f, -GUIManager.TopPadding);
            else
                WindowOffset = new Vector2(0f, 0f);

            headerText = header;
            bodyText = body;
            beginTime = Time.realtimeSinceStartup;
            Shown = true;
        }
    }
}
